<?php

$path = @$_REQUEST['path'];
$w = intval(@$_REQUEST['w']);
$h = intval(@$_REQUEST['h']);

if (!$path || !$w || !$h) return;

include('../tinymvc/myfiles/plugins/tinymvc_script_imageutil.php');

$source_root = $root = dirname(__FILE__).'/res';

$image = "$root/$path-{$w}x{$h}.jpg";
if (Imageutil::convertImage($source_root.'/'.$path.'.jpg', $image, $w.'x'.$h)) {

  if (!file_exists($image)) {
    header("HTTP/1.0 404 Not Found");
    exit();
  }

  $fsize = filesize($image);
  header('Content-Type: image/jpeg');
  header('Content-Length: '.$fsize);
  $file = @fopen($image,"rb");
  if ($file) {
    while(!feof($file)) {
      echo(fread($file, 2*1024));
      flush();
      if (connection_status()!=0) {
        @fclose($file);
        return  false;
      }
    }
    @fclose($file);
  }
}
var_dump($image);
var_dump(file_exists($image));
